package com.lhy.vip.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.lhy.vip.domain.VipMoney;
import com.lhy.vip.service.VipMoneyService;
import com.lhy.vip.mapper.VipMoneyMapper;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;


import java.util.List;

/**
* @author lhy
* @description 针对表【vip_money】的数据库操作Service实现
* @createDate 2024-07-29 16:50:26
*/
@Service
public class VipMoneyServiceImpl implements VipMoneyService{
    @Autowired
    private VipMoneyMapper iVipMoneyMapper;

    @Override
    public List<VipMoney> selectAll() {
        LambdaQueryWrapper <VipMoney> lqw = new LambdaQueryWrapper<>();
        lqw.eq(VipMoney::getIsDelete,0);
        return iVipMoneyMapper.selectList(lqw);
    }


    @Override
    public List<VipMoney> selectList(VipMoney iVipMoney) {
        LambdaQueryWrapper <VipMoney> lqw = this.lqw(iVipMoney);
        return iVipMoneyMapper.selectList(lqw);
    }

    @Override
    public Integer insert(VipMoney iVipMoney) {
        return iVipMoneyMapper.insert(iVipMoney);
    }

    @Override
    @Transactional
    public Integer delete(String ids) {
        try {
            String[] split = ids.split(",");
            for (String id : split) {
                VipMoney iVipMoney = new VipMoney();
                iVipMoney.setId(Long.parseLong(id));
                iVipMoney.setIsDelete(1);
                iVipMoneyMapper.updateById(iVipMoney);
            }
            return 1;
        }catch (Exception e){
            return -1;
        }
    }

    @Override
    public Integer update(VipMoney iVipMoney) {
        return iVipMoneyMapper.updateById(iVipMoney);
    }

    @Override
    public Page<VipMoney> pageAll(Integer page, Integer size) {
        PageHelper.startPage(page,size);
        return (Page<VipMoney>)this.selectAll();
    }

    @Override
    public Page<VipMoney> pageList(VipMoney iVipMoney, Integer page, Integer size) {
        PageHelper.startPage(page,size);
        return (Page<VipMoney>)this.selectList(iVipMoney);
    }

    public LambdaQueryWrapper lqw(VipMoney iVipMoney){
        LambdaQueryWrapper <VipMoney> lqw = new LambdaQueryWrapper<>();
        if (iVipMoney.getId() != null){
            lqw.eq(VipMoney::getId,iVipMoney.getId());
        }
        if (iVipMoney.getVipName() != null){
            lqw.eq(VipMoney::getVipName,iVipMoney.getVipName());
        }
        if (iVipMoney.getChangeMoney() != null){
            lqw.eq(VipMoney::getChangeMoney,iVipMoney.getChangeMoney());
        }
        if (iVipMoney.getCreateTime() != null){
            lqw.eq(VipMoney::getCreateTime,iVipMoney.getCreateTime());
        }
        if (iVipMoney.getClassify() != null){
            lqw.eq(VipMoney::getClassify,iVipMoney.getClassify());
        }
        if (iVipMoney.getContent() != null){
            lqw.eq(VipMoney::getContent,iVipMoney.getContent());
        }
        return lqw;
    }
}




